package com.wf.imgshow.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

public class ImgConfigUtil {

	public static String getImgConfig(){
		String html="";
		//获取配置文件
		String path =System.getProperty("user.dir");
		Properties props = new Properties();
		FileInputStream in;
		try {
			in = new FileInputStream(path+"/imgconfig.properties");
			 BufferedReader bf = new BufferedReader(new  InputStreamReader(in, "UTF-8"));
	         props.load(bf);
	         html=props.getProperty("html");
		} catch (Exception e) {
			System.out.println("读取配置错误"+e);
		}
		return html;
	}
	
	/**
	 * 写入配置
	 */
	public static void setImgCoinfig(String msg){
		Properties prop = new Properties();    
		try {
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			FileOutputStream oFile = new FileOutputStream("ipconfig.properties", true);//true表示追加打开
			prop.setProperty("ip", msg);
			prop.store(oFile, "Date:"+sdf.format(new Date(System.currentTimeMillis())));//注释
			oFile.close();
		} catch (Exception e) {
			System.out.println("更新配置错误"+e);
		}
	}
	
	/**
	 * 获取resources下配置文件
	 * 作者:王锋
	 * 时间:2017年12月8日
	 */
	public void getResources() throws IOException{
		Properties prop = new Properties();
		prop.load(this.getClass().getResourceAsStream("/ipconfig.properties"));
	}
	
}
